import {
  PropertyValue,
  StatusValue,
  ActionListValue,
  ActionIconValue,
  ActionButtonValue,
  MenuValue,
  DialogConfig,
  ComponentValue,
  TableConfig,
  TABLE_THEME,
} from 'kubeflow';
import { ServerTypeComponent } from './server-type/server-type.component';

// --- Configs for the Confirm Dialogs ---
export function getDeleteDialogConfig(name: string): DialogConfig {
  return {
    title: `是否确实要删除此 notebook server? ${name}`,
    message: `警告:如果notebook server发生故障，您的数据可能会丢失不受持久存储的支持`,
    accept: `删除`,
    confirmColor: 'warn',
    cancel: `取消`,
    error: '',
    applying: `正在删除`,
    width: '600px',
  };
}

export function getStopDialogConfig(name: string): DialogConfig {
  return {
    title: `是否确实要停止此notebook server? ${name}`,
    message: `Warning: 如果notebook server发生故障，您的数据可能会丢失不受持久存储的支持.`,
    accept: `停止`,
    confirmColor: 'primary',
    cancel: `取消`,
    error: '',
    applying: `正在停止`,
    width: '600px',
  };
}

// --- Config for the Resource Table ---
export const defaultConfig: TableConfig = {
  columns: [
    {
      matHeaderCellDef: `状态`,
      matColumnDef: 'status',
      value: new StatusValue(),
    },
    {
      matHeaderCellDef: `名称`,
      matColumnDef: 'name',
      style: { width: '25%' },
      value: new PropertyValue({
        field: 'name',
        tooltipField: 'name',
        truncate: true,
      }),
    },
    {
      matHeaderCellDef: `类型`,
      matColumnDef: 'type',
      value: new ComponentValue({
        component: ServerTypeComponent,
      }),
    },
    {
      matHeaderCellDef: `日期`,
      matColumnDef: 'age',
      style: { width: '12%' },
      textAlignment: 'right',
      value: new PropertyValue({ field: 'age', truncate: true }),
    },
    {
      matHeaderCellDef: `镜像`,
      matColumnDef: 'image',
      style: { width: '30%' },
      value: new PropertyValue({
        field: 'shortImage',
        popoverField: 'image',
        truncate: true,
        style: { maxWidth: '300px' },
      }),
    },
    {
      matHeaderCellDef: `GPUs`,
      matColumnDef: 'gpus',
      style: { width: '8%' },
      textAlignment: 'right',
      value: new PropertyValue({
        field: 'gpus.count',
        tooltipField: 'gpus.message',
      }),
    },
    {
      matHeaderCellDef: `CPUs`,
      matColumnDef: 'cpu',
      style: { width: '8%' },
      textAlignment: 'right',
      value: new PropertyValue({ field: 'cpu' }),
    },
    {
      matHeaderCellDef: `存储`,
      matColumnDef: 'memory',
      style: { width: '8%' },
      textAlignment: 'right',
      value: new PropertyValue({ field: 'memory' }),
    },
    {
      matHeaderCellDef: `容量`,
      matColumnDef: 'volumes',
      value: new MenuValue({ field: 'volumes', itemsIcon: 'storage' }),
    },

    {
      matHeaderCellDef: '',
      matColumnDef: 'actions',
      value: new ActionListValue([
        new ActionButtonValue({
          name: 'connect',
          tooltip: `连接此记事本服务器`,
          color: 'primary',
          field: 'connectAction',
          text: `连接`,
        }),
        new ActionIconValue({
          name: 'start-stop',
          tooltipInit: `停止此 记事本服务器`,
          tooltipReady: `开启 记事本服务器`,
          color: '',
          field: 'startStopAction',
          iconInit: 'material:stop',
          iconReady: 'material:play_arrow',
        }),
        new ActionIconValue({
          name: 'delete',
          tooltip: `删除此记事本服务器`,
          color: '',
          field: 'deleteAction',
          iconReady: 'material:delete',
        }),
      ]),
    },
  ],
};
